package com.cefa.edu.service;

import com.cefa.edu.dao.SchoolMapper;
import com.cefa.edu.dao.StudentStageDataMapper;
import com.cefa.edu.dao.UserOrganRoleMapper;
import com.cefa.edu.pojo.*;
import com.cefa.edu.pojo.Course;
import com.cefa.edu.pojo.Role;
import com.cefa.edu.pojo.School;
import com.cefa.edu.pojo.Score;
import com.cefa.edu.pojo.User;
import com.cefa.edu.util.PinYinUtil;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cefa.edu.pojo.Class;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class FrameworkService {

    private final static Logger logger = LoggerFactory.getLogger(FrameworkService.class);

    @Autowired
    private UserOrganRoleMapper userOrganRoleMapper;

    @Autowired
    private SchoolMapper schoolMapper;
    @Autowired
    StudentStageDataMapper studentStageDataMapper;

    public List<Map<String, Object>> getFrameworkOfTeacher(UserOrganRole resourse) {

        List<Map<String, Object>> structure = new ArrayList<>();
        if (resourse.getSchoolId() == null && resourse.getPhaseId() == null && resourse.getGradeId() == null && resourse.getClassId() == null && resourse.getStudentId() == null) {
            structure = findSchoolPhases(resourse);
        } else if (resourse.getSchoolId() != null && resourse.getPhaseId() != null && resourse.getGradeId() == null && resourse.getClassId() == null && resourse.getStudentId() == null) {
            structure = findPhaseGrade(resourse);
        } else if (resourse.getSchoolId() != null && resourse.getPhaseId() != null && resourse.getGradeId() != null && resourse.getClassId() == null && resourse.getStudentId() == null) {
            structure = findGradeClass(resourse);
        } else if (resourse.getSchoolId() != null && resourse.getPhaseId() != null && resourse.getGradeId() != null && resourse.getClassId() != null && resourse.getStudentId() == null) {
            structure = findTeachersAndStudentsAtClass(resourse);
        } else if (resourse.getSchoolId() != null && resourse.getPhaseId() != null && resourse.getGradeId() != null && resourse.getClassId() != null && resourse.getStudentId() != null) {
            structure = findStudentCourses(resourse);
        }
        return structure;
    }


    /**
     * @param resourse
     * @return s查找学校下的教育阶段, 展开到教育阶段
     */
    public List<Map<String, Object>> findSchoolPhases(UserOrganRole resourse) {

        List<Integer> schoolIds = userOrganRoleMapper.findSchoolIds(resourse.getUserId());
        Map<Integer, School> schoolUniqueMap = getSchoolUniqueMap();

        ArrayList<Map<String, Object>> resultList = new ArrayList<>();

        for (Integer schoolId : schoolIds) {

            HashMap<String, Object> phaseMap = new HashMap<>();
            List<Integer> phaseIds = userOrganRoleMapper.findPhaseIds(resourse.getUserId(), schoolId);
            Integer teacherNumber = userOrganRoleMapper.getTeacherNumber(schoolId);
            Integer studentNumber = userOrganRoleMapper.getSchoolStudentNumber(schoolId);

            Map<Integer, Phase> phaseUniqueMap = getPhaseUniqueMap(schoolId);
            phaseMap.put("schoolId", schoolId);
            phaseMap.put("schoolName", schoolUniqueMap.get(schoolId).getSchoolName());
            phaseMap.put("teacherNumber", teacherNumber);
            phaseMap.put("studentNumber", studentNumber);

            if (phaseIds.contains(0)) {
                List<Phase> phases = userOrganRoleMapper.findPhases(schoolId);
                List<Phase> phaseAddTeacherNumber = getPhaseTeacherNumber(phases, schoolId);

                Map<String, Phase> phaseIndex = Maps.uniqueIndex(phaseAddTeacherNumber, new Function<Phase, String>() {
                            @Override
                            public String apply(Phase phase) {
                                return PinYinUtil.getPingYin(phase.getPhaseName());
                            }
                        }
                );
                phaseMap.put("phases", phaseIndex);
            } else {
                ArrayList<Phase> phase = new ArrayList<>();
                for (Integer phaseId : phaseIds) {
                    List<Integer> gradeIds = userOrganRoleMapper.findGradeIdsByPhaseId(resourse.getUserId(), schoolId, phaseId);
                    Phase phaseVisible = phaseUniqueMap.get(phaseId);
                    phaseVisible.setPhaseVisible(true);
                    /*
                    if (gradeIds.contains(0)) {
                        phaseVisible.setPhaseVisible(true);
                    } else {
                        phaseVisible.setPhaseVisible(false);
                    }*/
                    phase.add(phaseVisible);
                }
                Map<String, Phase> phaseIndex = Maps.uniqueIndex(phase, new Function<Phase, String>() {
                    @Override
                    public String apply(Phase phase) {
                        return PinYinUtil.getPingYin(phase.getPhaseName());
                    }
                });
                phaseMap.put("phases", phaseIndex);
            }
            resultList.add(phaseMap);
        }
        return resultList;
    }


    /**
     * @param resourse
     * @return s根据教育阶段查找此教育阶段下面的年级, 展开到年级
     */
    private List<Map<String, Object>> findPhaseGrade(UserOrganRole resourse) {
        ArrayList<Map<String, Object>> result = new ArrayList<>();
        HashMap<String, Object> resultMap = new HashMap<>();

        Integer schoolId = resourse.getSchoolId();
        Integer phaseId = resourse.getPhaseId();
        Map<String, Grade> gradeUniqueMap = getGradeUniqueMap(schoolId, phaseId);

        List<ManagerRoleInfo> phaseManagers = findPhaseManagers(schoolId, phaseId);
        resultMap.put("phaseManagers", phaseManagers);

        List<Integer> phaseIds = userOrganRoleMapper.findPhaseIds(resourse.getUserId(), schoolId);
        HashMap<String, Grade> gradeHashMap = new HashMap<>();
        if (phaseIds.contains(0)) {
            resultMap.put("grades", gradeUniqueMap);
            result.add(resultMap);
        } else {
            List<Integer> gradeIds = userOrganRoleMapper.findGradeIdsByPhaseId(resourse.getUserId(), schoolId, phaseId);
            if (gradeIds.contains(0)) {
                resultMap.put("grades", gradeUniqueMap);
                result.add(resultMap);
            } else {
                for (Integer gradeId : gradeIds) {
                    for (String gradeName : gradeUniqueMap.keySet()) {
                        Grade grade = gradeUniqueMap.get(gradeName);


                        if (grade.getId().equals(gradeId)) {
                            List<Integer> classIds = userOrganRoleMapper.findClassIdsByGradeId(resourse.getUserId(), schoolId, phaseId, gradeId);
                            if (classIds.contains(0)) {
                                grade.setGradeVisible(true);
                            } else {
                                grade.setGradeVisible(false);
                            }
                            gradeHashMap.put(gradeName, grade);
                        }
                       // grade.setGradeVisible(true);
                        //gradeHashMap.put(gradeName, grade);
                    }
                }
                resultMap.put("grades", gradeHashMap);
                result.add(resultMap);
            }
        }
        return result;
    }


    /**
     * @param schoolId
     * @param phaseId
     * @return s查找教育阶段管理者
     */
    private List<ManagerRoleInfo> findPhaseManagers(Integer schoolId, Integer phaseId) {
        String phaseIds = phaseId + "," + 0;
        return userOrganRoleMapper.findPhaseManagers(schoolId, phaseIds);
    }


    /**
     * @param resourse
     * @return s根据学校id、教育阶段id、年级id，查询此年级下面的班级信息,展开到班级
     */
    private List<Map<String, Object>> findGradeClass(UserOrganRole resourse) {
        ArrayList<Map<String, Object>> result = new ArrayList<>();
        HashMap<String, Object> resultMap = new HashMap<>();

        Integer schoolId = resourse.getSchoolId();
        Integer phaseId = resourse.getPhaseId();
        Integer gradeId = resourse.getGradeId();

        Map<Integer, Class> classUniqueMap = getClassUniqueMap(schoolId, phaseId, gradeId);

        List<ManagerRoleInfo> gradeManagers = findGradeManagers(schoolId, phaseId, gradeId);
        resultMap.put("gradeManagers", gradeManagers);

        List<Course> coursesOfGrade = userOrganRoleMapper.findCoursesOfGrade(schoolId, gradeId);
        resultMap.put("coursesOfGrade", coursesOfGrade);

        List<Integer> phaseIds = userOrganRoleMapper.findPhaseIds(resourse.getUserId(), schoolId);

        if (phaseIds.contains(0)) {
            resultMap.put("classes", classUniqueMap);
            result.add(resultMap);
        } else {
            List<Integer> gradeIds = userOrganRoleMapper.findGradeIdsByPhaseId(resourse.getUserId(), schoolId, phaseId);
            if (gradeIds.contains(0)) {
                resultMap.put("classes", classUniqueMap);
                result.add(resultMap);
            } else {
                List<Integer> classIds = userOrganRoleMapper.findClassIdsByGradeId(resourse.getUserId(), schoolId, phaseId, gradeId);
                if (classIds.contains(0)) {
                    resultMap.put("classes", classUniqueMap);
                    result.add(resultMap);
                } else {
                    HashMap<Integer, Class> givenMap = new HashMap<>();
                    for (Integer cla : classIds) {
                        givenMap.put(cla, classUniqueMap.get(cla));
                    }
                    resultMap.put("classes", givenMap);
                    result.add(resultMap);
                }
            }
        }
        return result;
    }

    /**
     * @param schoolId
     * @param phaseId
     * @param gradeId
     * @return s查询年级的管理者
     */
    private List<ManagerRoleInfo> findGradeManagers(Integer schoolId, Integer phaseId, Integer gradeId) {
        String phaseIds = phaseId + "," + 0;
        String gradeIds = gradeId + "," + 0;
        return userOrganRoleMapper.findGradeManagers(schoolId, phaseIds, gradeIds);
    }

    /**
     * @param resourse
     * @return s根据学校id、教育阶段id、年级id、班级id,查询此班级下面的所有的教师信息和学生信息
     */
    private List<Map<String, Object>> findTeachersAndStudentsAtClass(UserOrganRole resourse) {
        ArrayList<Map<String, Object>> result = new ArrayList<>();
        HashMap<String, Object> resultMap = new HashMap<>();

        Integer schoolId = resourse.getSchoolId();
        Integer phaseId = resourse.getPhaseId();
        Integer gradeId = resourse.getGradeId();
        Integer classId = resourse.getClassId();

        List<Instructor> director = userOrganRoleMapper.findDirectorOfClass(schoolId, phaseId, gradeId, classId);
        List<Instructor> teachers = userOrganRoleMapper.findTeachersOfClass(schoolId, phaseId, gradeId, classId);
        List<User> students = userOrganRoleMapper.findStudentsOfClass(schoolId, phaseId, gradeId, classId);

        /*students所有学生(毕业和未毕业的)
       List<Integer> graduateIds=studentStageDataMapper.getGraduateIds();
        //过滤到results集合中毕业生
        List<User> newResults=null;
        if(students!=null && students.size()>0){
            //filter
            if(graduateIds!=null && graduateIds.size()>0){
                newResults=new ArrayList<User>();
                for(User stuBean:students){
                    if(!graduateIds.contains(stuBean.getId())){
                        newResults.add(stuBean);
                    }
                }
            }
        }// if(results!=null && results.size()>0){
        */
        for (Instructor teacher : teachers) {
            if(director!=null && director.size()>0){
              for(Instructor bean:director){
                  if(bean.getId().equals(teacher.getId())){
                      teacher.setDirectorStatus(true);
                  }
              }
            }

            /*
            if (director != null && director.size() != 0 && director.get(0).getId().equals(teacher.getId())) {
                teacher.setDirectorStatus(true);
            } else {
                teacher.setDirectorStatus(false);
            }*/
        }

        resultMap.put("teachers", teachers);
       // resultMap.put("students", (graduateIds==null ||graduateIds.size()==0)?students:newResults);
        resultMap.put("teacherNumber", teachers.size());
        resultMap.put("students", students);
        resultMap.put("studentNumber", students.size());
        result.add(resultMap);
        return result;
    }


    public Map<String, Object> getFrameworkOfStudent(UserOrganRole resource) {
        HashMap<String, Object> structure = new HashMap<>();
        return structure;
    }


    /**
     * @return s查询所有的学校信息
     */
    public Map<Integer, School> getSchoolUniqueMap() {
        List<School> schools = schoolMapper.findSchoolInfo();
        return Maps.uniqueIndex(schools, new Function<School, Integer>() {
            @Override
            public Integer apply(School school) {
                return school.getId();
            }
        });
    }


    /**
     * @param schoolId
     * @return s根据学校id查询这个学校下面的所有的教育阶段
     */
    public Map<Integer, Phase> getPhaseUniqueMap(Integer schoolId) {
        List<Phase> phases = userOrganRoleMapper.findPhases(schoolId);
        List<Phase> phaseAddTeacherNumber = getPhaseTeacherNumber(phases, schoolId);
        return Maps.uniqueIndex(phaseAddTeacherNumber, new Function<Phase, Integer>() {
            @Override
            public Integer apply(Phase phase) {
                return phase.getId();
            }
        });
    }


    /**
     * @param phases
     * @param schoolId
     * @return s查找教育阶段下面的下面的教师人数
     */
    public List<Phase> getPhaseTeacherNumber(List<Phase> phases, Integer schoolId) {
        ArrayList<Phase> result = new ArrayList<>();
        for (Phase phase : phases) {
            Integer teacherNumber = userOrganRoleMapper.getPhaseTeacherNumber(phase.getId(), schoolId);
            Integer studentNumber = userOrganRoleMapper.getPhaseStudentNumber(phase.getId(), schoolId);
            phase.setTeacherNumber(teacherNumber);
            phase.setStudentNumber(studentNumber);
            result.add(phase);
        }
        return result;
    }

    /**
     * @param schoolId
     * @param phaseId
     * @return s根据学校id和教育阶段id查询此教育阶段下面的所有的年级信息
     */
    public Map<String, Grade> getGradeUniqueMap(Integer schoolId, Integer phaseId) {
        List<Grade> grades = userOrganRoleMapper.findAllGradeAtPhase(schoolId, phaseId);
        for (Grade grade : grades) {
            grade.setGradeNameChina(grade.getGradeDate() + "级");
            Integer gradeTeacherNumber = userOrganRoleMapper.getGradeTeacherNumber(grade.getSchoolId(), phaseId, grade.getId());
            Integer gradeStudentNumber = userOrganRoleMapper.getGradeStudentNumber(grade.getSchoolId(), phaseId, grade.getId());
            grade.setTeacherNumber(gradeTeacherNumber);
            grade.setStudentNumber(gradeStudentNumber);
        }
        return Maps.uniqueIndex(grades, new Function<Grade, String>() {
            @Override
            public String apply(Grade grade) {
                return PinYinUtil.getPingYin(grade.getGradeName());
            }
        });
    }


    /**
     * @param schoolId
     * @param phaseId
     * @param gradeId
     * @return s根据学校id、教育阶段id、年级id查询此年级下面的所有班级
     */
    private Map<Integer, Class> getClassUniqueMap(Integer schoolId, Integer phaseId, Integer gradeId) {
        List<Class> classes = userOrganRoleMapper.findAllClassAtGrade(schoolId, phaseId, gradeId);

        for (Class cla : classes) {
            Integer teacherNumber = userOrganRoleMapper.getClassTeacherNumber(schoolId, phaseId, gradeId, cla.getId());
            Integer studentNumber = userOrganRoleMapper.getClassStudentNumber(schoolId, phaseId, gradeId, cla.getId());
            cla.setTeacherNumber(teacherNumber);
            cla.setStudentNumber(studentNumber);
        }

        return Maps.uniqueIndex(classes, new Function<Class, Integer>() {
            @Override
            public Integer apply(Class cla) {
                return cla.getId();
            }
        });
    }


    /**
     * @param resourse
     * @return s根据学校id、教育阶段id、年级id、班级id、学生id查询学生的课程
     */
    private List<Map<String, Object>> findStudentCourses(UserOrganRole resourse) {
        ArrayList<Map<String, Object>> result = new ArrayList<>();
        HashMap<String, Object> resultMap = new HashMap<>();

        Integer schoolId = resourse.getSchoolId();
        Integer phaseId = resourse.getPhaseId();
        Integer gradeId = resourse.getGradeId();
        Integer classId = resourse.getClassId();
        Integer studentId = resourse.getStudentId();

        List<Course> course = userOrganRoleMapper.findStudentCourse(schoolId, phaseId, gradeId, classId, studentId);

        Map<String, Course> courseIndexMap = Maps.uniqueIndex(course, new Function<Course, String>() {
            @Override
            public String apply(Course course) {
                return PinYinUtil.getPingYin(course.getCourseName());
            }
        });
        resultMap.put("courses", courseIndexMap);
        result.add(resultMap);
        return result;
    }


    @Transactional("transactionManager")
    public Score saveStudentScore(Score score, Integer schoolId, Integer loginUserId) {

        User user = userOrganRoleMapper.findUserById(loginUserId);
        Role userRole = userOrganRoleMapper.getUserRoleForScore(schoolId, loginUserId);

        score.setRecordingPerson(user.getName() + "(" + userRole.getRoleNameChinese() + ")");
        String recodingTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        score.setRecordingTime(recodingTime);
        userOrganRoleMapper.saveStudentScore(score);
        return score;
    }


    /**
     * @param source
     * @return s模糊搜索学生信息
     */
    public List<Map<String, Object>> searchStudent(StudentInformation source) {
        ArrayList<Map<String, Object>> result = new ArrayList<>();
        HashMap<String, Object> resultMap = new HashMap<>();

        Integer loginUserId = source.getLoginUserId();
        Integer schoolId = source.getSchoolId();
        String searchText = source.getSearchText();
        List<StudentInformation> studentInformations = userOrganRoleMapper.findAllStudentInfo(schoolId);

        Map<Integer, StudentInformation> studentInformationsMap = Maps.uniqueIndex(studentInformations, new Function<StudentInformation, Integer>() {
            @Override
            public Integer apply(StudentInformation studentInformation) {
                return studentInformation.getId();
            }
        });

        Set<Integer> studentIds = findStudentIdsOfLoginUser(loginUserId, schoolId);

        ArrayList<StudentInformation> results = new ArrayList<>();
        Integer phaseId = source.getPhaseId();
        Integer gradeId = source.getGradeId();
        Integer classId = source.getClassId();
        String searchName = source.getSearchText();


        for (StudentInformation student : studentInformations) {
            if(!studentIds.contains(student.getId())){
                 continue;
            }

            if(StringUtils.isNotBlank(searchName)){
                //searchName不为空 学习阶段 、年级、班级 参数为空吗？
                if(phaseId != null&&gradeId==null){
                    if (student.getName().contains(searchName)&& phaseId.equals(student.getPhaseId())) {
                        results.add(student);
                    }
                }else if(phaseId != null&&gradeId!=null&&classId==null){
                    if (student.getName().contains(searchName)&& phaseId.equals(student.getPhaseId())&&gradeId.equals(student.getGradeId())) {
                        results.add(student);
                    }
                }else  if(phaseId != null&&gradeId!=null&&classId!=null){
                    if (student.getName().contains(searchName)&& phaseId.equals(student.getPhaseId())&&gradeId.equals(student.getGradeId())&&classId.equals(student.getClassId())) {
                        results.add(student);
                    }
                }else  if (student.getName().contains(searchName)) {
                    results.add(student);
                }
            }else {//searchName为空
                if(phaseId!=null && gradeId == null){//获取指定学校阶段下学生 add by chaijian 2018-09-25
                    if (phaseId.equals(student.getPhaseId())) {
                        results.add(student);
                    }
                }else if(phaseId != null && gradeId != null &&classId==null){//有年级参数 获取该年级下的学生 add by chaijian 2018-09-25
                    if (phaseId.equals(student.getPhaseId())&& gradeId.equals(student.getGradeId())) {
                        results.add(student);
                    }
                } else if (phaseId != null && gradeId != null && classId != null) {
                    if (phaseId.equals(student.getPhaseId()) && gradeId.equals(student.getGradeId()) && classId.equals(student.getClassId()) && student.getName().contains(searchName)) {
                        results.add(student);
                    }
                }else if(phaseId == null && gradeId == null && classId == null){
                    results.add(student);
                }
            }


            /*
            if (phaseId != null && gradeId != null && classId != null && searchName == null) {
                if (phaseId.equals(student.getPhaseId()) && gradeId.equals(student.getGradeId()) && classId.equals(student.getClassId())) {
                    results.add(student);
                }
            } else if (phaseId != null && gradeId != null && classId != null) {
                if (phaseId.equals(student.getPhaseId()) && gradeId.equals(student.getGradeId()) && classId.equals(student.getClassId()) && student.getName().contains(searchName)) {
                    results.add(student);
                }
            } else if (phaseId == null && gradeId == null && classId == null && searchName != null) {
                if (student.getName().contains(searchName)) {
                    results.add(student);
                }
            }*/
        }

        //过滤到results集合中毕业生
      //  List<Integer> graduateIds=studentStageDataMapper.getGraduateIds();
       // List<StudentInformation> newResults=this.filterGraduatesFromAllStudents(results,graduateIds);

        if(results!=null && results.size()>0){
            Integer pageNo = source.getPageNo();
            Integer pageCount = source.getPageCount();
            if (pageNo != null && pageCount != null) {
                resultMap.put("totalPage", (results.size() - 1) / pageCount + 1);
                results = new ArrayList<>(results.subList((pageNo - 1) * pageCount, pageCount * pageNo > results.size() ? results.size() : pageCount * pageNo));
            }
        }
        resultMap.put("students", results);

        result.add(resultMap);
        return result;

    }

    //过滤到results集合中毕业生
    private List<StudentInformation> filterGraduatesFromAllStudents(List<StudentInformation> results, List<Integer> graduateIds) {
        List<StudentInformation> newResults=null;
        if(results!=null && results.size()>0){
            //filter
            if(graduateIds!=null && graduateIds.size()>0){
                newResults=new ArrayList<StudentInformation>();
                for(StudentInformation stuBean:results){
                    if(!graduateIds.contains(stuBean.getId())){
                        newResults.add(stuBean);
                    }
                }
            }else {
                return  results;
            }
        }// if(results!=null && results.size()>0){
        return newResults;
    }


    /**
     * @param loginUserId
     * @param schoolId
     * @return s查找登陆的用户所拥有的学生的权限
     */
    private Set<Integer> findStudentIdsOfLoginUser(Integer loginUserId, Integer schoolId) {
        List<UserOrganRole> userOrganRoles = userOrganRoleMapper.findRoleIdsOfUser(loginUserId, schoolId);
        HashSet<Integer> students = new HashSet<>();
        for (UserOrganRole userOrganRole : userOrganRoles) {
            Integer roleType = userOrganRole.getRoleType();
            if (roleType == 1) {
                List<Integer> studentIdsOfSchool = userOrganRoleMapper.findAllStudentIds(schoolId);
                students.addAll(studentIdsOfSchool);
            } else if (roleType == 2) {
                List<Integer> studentIdsOfPhase = userOrganRoleMapper.findAllStudentsIdsOfPhase(schoolId, userOrganRole.getPhaseId());
                students.addAll(studentIdsOfPhase);
            } else if (roleType == 3) {
                List<Integer> studentIdsOfGrade = userOrganRoleMapper.findAllStudentsIdsOfGrade(schoolId, userOrganRole.getPhaseId(), userOrganRole.getGradeId());
                students.addAll(studentIdsOfGrade);
            } else if (roleType == 4 || roleType == 5) {
                List<Integer> studentIdsOfClass = userOrganRoleMapper.findAllStudentsIdsOfClass(schoolId, userOrganRole.getPhaseId(), userOrganRole.getGradeId(), userOrganRole.getClassId());
                students.addAll(studentIdsOfClass);
            }
        }
        return students;
    }

    /**
     * @param studentInformation
     * @return s查询年级下面的课程
     */
    public List<Course> searchCourses(StudentInformation studentInformation) {
        List<Course> courseList=userOrganRoleMapper.searchCourses(studentInformation.getSchoolId(), studentInformation.getGradeId());

        //若登陆人是班主任 只返回授课老师、和班主任所教科目数据
        List<Integer> courseIdList=null;
        if(studentInformation.getUserId()!=null&&studentInformation.getUserId()!=0){//是老师
            courseIdList=userOrganRoleMapper.getCourseIdListWithUserIdAndGradeIdAndSchoolId(studentInformation.getUserId(),studentInformation.getGradeId(),studentInformation.getSchoolId());

          if(courseIdList!=null && courseIdList.size()>0){
                if(courseList!=null && courseList.size()>0){
                    List<Course> filterCourseList =new ArrayList<>();
                    for(Course course:courseList){
                        if(courseIdList.contains(course.getId())){
                            filterCourseList.add(course);
                        }
                    }
                    return filterCourseList;
                }
          }else{
              return null;
          }
        }else {
            //非老师
            return courseList;
        }
       return null;
    }

    public Integer checkStudentScoreExist(Score score) {
        return userOrganRoleMapper.checkStudentScoreExist(score.getUserId(),
                score.getPhaseId(), score.getGradeId(), score.getClassId(), score.getCourseId(), score.getRecordingName());
    }
}


















